package org.hanbo.code.repository.exception;

import java.io.PrintWriter;
import java.io.StringWriter;

public class ErrorDescription
{
	private int errorCode;
	private String errorType;
	private String errorDesc;
	private String exceptionDesc;
	private String exceptionStackTrace;
	
	public ErrorDescription()
	{
	}
	
	public ErrorDescription(int errorCode, Exception exception)
	{
		this.errorCode = errorCode;
		this.errorType = "Operational";
		this.errorDesc = exception.getClass().getName();
		this.setExceptionDesc(exception.getMessage());
		this.setExceptionStackTrace(exception);
	}

	public ErrorDescription(CodeSnippetExceptionBase exception)
	{
		this.errorCode = exception.getErrorCode();
		this.errorType = exception.getErrorType();
		this.errorDesc = exception.getErrorDescription();
		this.setExceptionDesc(exception.getMessage());
		this.setExceptionStackTrace(exception);
	}

	public void setErrorCode(int errorCode)
	{
		this.errorCode = errorCode;
	}

	public int getErrorCode()
	{
		return errorCode;
	}

	public void setErrorType(String errorType)
	{
		this.errorType = errorType;
	}

	public String getErrorType()
	{
		return errorType;
	}

	public void setErrorDesc(String errorDesc)
	{
		this.errorDesc = errorDesc;
	}

	public String getErrorDesc()
	{
		return errorDesc;
	}

	public void setExceptionDesc(String exceptionDesc)
	{
		this.exceptionDesc = exceptionDesc;
	}

	public String getExceptionDesc()
	{
		return exceptionDesc;
	}

	public void setExceptionStackTrace(Exception exception)
	{
		StringWriter sw = new StringWriter();
		exception.printStackTrace(new PrintWriter(sw));
		this.exceptionStackTrace = sw.toString();
	}
	
	public void setExceptionStackTrace(String exceptionStackTrace)
	{
		this.exceptionStackTrace = exceptionStackTrace;
	}

	public String getExceptionStackTrace()
	{
		return exceptionStackTrace;
	}
}
